<?php
namespace Home\Controller;
use Home\Common\Common;
class RecordController extends Common
{
    /**
     * 员工调遣记录显示
     */
    public function show()
    {
        $sta = M('staffinfo')->join('`departmentinfo` on `departmentinfo`.dpt_id=`staffinfo`.dpt_id')->join('`postinfo` on `postinfo`.pt_id=`staffinfo`.pt_id')->select();
        $this->assign('sta', $sta);
        $recordinfo = M('recordinfo');
        //计页数、分页
        $count = $recordinfo->where('state=1')->count();
        $page = new \Think\Page($count,10);
        $show = $page->show();
        $rec = $recordinfo->where('state=1')->limit($page->firstRow.','.$page->listRows)->order('rmd_id')->select();
        if($rec){
            $dpt = M('departmentinfo')->join('`postinfo` on `postinfo`.dpt_id=`departmentinfo`.dpt_id')->where('`departmentinfo`.dpt_id='.$rec[0]['dpt_aid'].' and `postinfo`.pt_id='.$rec[0]['pt_aid'])->select();
            $this->assign('dpt',$dpt);
        }
        $this->assign('rec',$rec);
        $this->assign('count',$count);
        $this->assign('show',$show);
        $this->display();
    }

    public function del()
    {
        if (empty($_GET['rmd_id'])) {
            $this->error('参数错误');
        } else {
            $record = M('recordinfo');
            $record->where('rmd_id=' . $_GET['rmd_id'])->save(array('state' => 0));
            $this->success('隐藏成功', U('show'));
        }
    }

    //批量隐藏
    public function del_all(){
        $record=M('recordinfo');
        if(empty($_GET['rmd_ids'])){
            $this->error('请选择需要隐藏的内容',U('show'));
        }
        $rmd_id=implode(',', $_GET['rmd_ids']);//获取id
        $rmd_ids=explode(',',$rmd_id);//去逗号
        foreach ($rmd_ids as $id){
            $record->where('rmd_id='.$id)->save(array('state'=>0));
        }
        $this->success('隐藏成功',U('show'));
    }
    public function pt_view(){
        $sta = M('staffinfo')->join('`departmentinfo` on `departmentinfo`.dpt_id=`staffinfo`.dpt_id')->join('`postinfo` on `postinfo`.pt_id=`staffinfo`.pt_id')->select();
        $this->assign('sta', $sta);
        $recordinfo = M('recordinfo');
        //计页数、分页
        $count = $recordinfo->where('state=0')->count();
        $page = new \Think\Page($count,10);
        $show = $page->show();
        $rec = $recordinfo->where('state=0')->limit($page->firstRow.','.$page->listRows)->order('rmd_id')->select();
        if($rec){
            $dpt = M('departmentinfo')->join('`postinfo` on `postinfo`.dpt_id=`departmentinfo`.dpt_id')->where('`departmentinfo`.dpt_id='.$rec[0]['dpt_aid'].' and `postinfo`.pt_id='.$rec[0]['pt_aid'])->select();
            $this->assign('dpt',$dpt);
        }
        $this->assign('rec',$rec);
        $this->assign('count',$count);
        $this->assign('show',$show);
        $this->display();
    }
    //显示信息
    public function xs(){
        if (empty($_GET['rmd_id']) && empty($_GET['state'])){
            $this->error('参数错误',U('pt_view'));
        }else{
            $record=M('recordinfo');
            $_GET['state']=1;//修改状态为1（显示）
            $record->save($_GET);
            $this->success('显示成功',U('pt_view'));
        }
    }
    //批量显示
    public function xs_all(){
        $record=M('recordinfo');
        if(empty($_GET['rmd_ids'])){
            $this->error('请选择需要显示的内容',U('pt_view'));
        }
        $rmd_ids = implode(',',$_GET['rmd_ids']);//获取id
        $str = explode(",",$rmd_ids);//去逗号
        foreach ($str as $a){//循环id
            $record->where(array('rmd_id'=>$a))->save(array('state'=>1));
        }
        $this->success('显示成功',U('pt_view'));
    }
    //删除信息
    public function delete(){
        if (empty($_GET['rmd_id']) && empty($_GET['state'])){
            $this->error('参数错误',U('pt_view'));
        }else{
            $record=M('recordinfo');
            $record->where('rmd_id='.$_GET['rmd_id'])->delete($_GET);
            $this->success('删除成功',U('pt_view'));
        }
    }
}
